package com.alks.function.controller.stockdept.pcfactorystockquery;

import com.alks.common.aop.ApiRestController;
import com.alks.common.aop.RoleCheck;
import com.alks.entity.data.response.ResponseInfo;
import com.alks.function.data.request.stockdept.pcfactorystockwork.*;
import com.alks.function.service.stockdept.pcfactorystockquery.IMtlToSurpService;
import com.alks.function.service.stockdept.pcfactorystockquery.IPcOtherMtlInService;
import com.alks.function.service.stockdept.pcfactorystockquery.IPcOtherMtlOutService;
import com.alks.function.service.stockdept.pcfactorystockquery.IPcSurplusService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.List;

@RestController
@ApiRestController("/pcFactorStockQuery")
@Api(value = "仓储部查询",tags = "仓储部-仓储工厂作业-剩料入库作业")
@RequiredArgsConstructor
@RoleCheck(prgIds = {"160113"})
public class MtlToSurpController {
    private final IMtlToSurpService service;
    private final IPcOtherMtlInService inService;
    private final IPcSurplusService surService;
    private final IPcOtherMtlOutService outService;

    @GetMapping("/getMTSTempQuery")
    @ApiOperation(value = "剩料入库作业-待入剩料仓材料明细-查询",tags = "仓储部-仓储工厂作业-剩料入库作业")
    public ResponseInfo getMTSTempQuery(){
        return service.getMTSTempQuery();
    }

    @PutMapping("/getMTSLotMtlQuery")
    @ApiOperation(value = "剩料入库作业-指令材料-分页可条件查询",tags = "仓储部-仓储工厂作业-剩料入库作业")
    public ResponseInfo getMTSLotMtlQuery(@RequestBody LotMtlRequest request) {
        return surService.getLotMtlQuery(request, 0);
    }

    @PutMapping("/getMTSComMtlQuery")
    @ApiOperation(value = "剩料入库作业-通用材料-分页可条件查询",tags = "仓储部-仓储工厂作业-剩料入库作业")
    public ResponseInfo getMTSComMtlQuery(@RequestBody LotComMtlRequest request) {
        return inService.getLotComMtlQuery(request);
    }

    @PutMapping("/getMTSStyleMtlQuery")
    @ApiOperation(value = "剩料入库作业-型体材料查询-分页可条件查询",tags = "仓储部-仓储工厂作业-剩料入库作业")
    public ResponseInfo getMTSStyleMtlQuery(@RequestBody StyMtlRequest request) {
        return outService.getStyMtlQuery2(request);
    }

    @PostMapping("/getMTSSubMtlQuery")
    @ApiOperation(value = "剩料入库作业-贴合子材料-条件查询", tags = "仓储部-仓储工厂作业-剩料入库作业")
    public ResponseInfo getMTSSubMtlQuery(@RequestParam String mtlNo) {
        return outService.otherLotSubMtlQuery2(mtlNo);
    }


    @PutMapping("/getMTSDetailQuery")
    @ApiOperation(value = "剩料入库作业-待入剩料仓材料明细-可条件查询",tags = "仓储部-仓储工厂作业-剩料入库作业")
    public ResponseInfo getMTSDetailQuery(@RequestBody SurpDetailRequest request){
        return service.getMTSDetailQuery(request);
    }

    @PutMapping("/mTSTempAdd")
    @ApiOperation(value = "剩料入库作业-转入待入剩料-新增",tags = "仓储部-仓储工厂作业-剩料入库作业")
    public ResponseInfo mTSTempAdd(@RequestBody List<OMtlwaitAddRequest> request,
                                   @RequestParam@ApiParam("1.通用 2.指令 3.型体 4.材料库") Integer type){
        return service.mTSTempAdd(request,type);
    }

    @PostMapping("/mTSTempUp")
    @ApiOperation(value = "剩料入库作业-待入剩料修改-更新",tags = "仓储部-仓储工厂作业-剩料入库作业")
    public ResponseInfo mTSTempUp(@RequestParam@ApiParam("材料号") String mtlNo,
                                   @RequestParam(required = false)@ApiParam("数量") BigDecimal qty,
                                   @RequestParam(required = false)@ApiParam("备注") String remark){
        return service.mTSTempUp(mtlNo,qty,remark);
    }

    @PostMapping("/mTSDetailAdd")
    @ApiOperation(value = "剩料入库作业-转入剩料仓材料明细-新增",tags = "仓储部-仓储工厂作业-剩料入库作业")
    public ResponseInfo mTSDetailAdd(@RequestParam@ApiParam("材料号") String mtlNo,
                                     @RequestParam@ApiParam("入库原因") String slipReason,
                                     @RequestParam@ApiParam("入库日期")@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate slipDate){
        return service.mTSDetailAdd(mtlNo,slipReason, slipDate.atStartOfDay());
    }

    @PostMapping("/mTSTempDelete")
    @ApiOperation(value = "剩料入库作业-待入剩料删除-删除",tags = "仓储部-仓储工厂作业-剩料入库作业")
    public ResponseInfo mTSTempDelete(@RequestParam@ApiParam("材料号") String mtlNo){
        return service.mTSTempDelete(mtlNo);
    }

    @PostMapping("/mTSDetailDelete")
    @ApiOperation(value = "剩料入库作业-删除当前行记录-删除",tags = "仓储部-仓储工厂作业-剩料入库作业")
    public ResponseInfo mTSDetailDelete(@RequestParam@ApiParam("入库单号") String slipNo,
                                        @RequestParam@ApiParam("材料号") String mtlNo){
        return service.mTSDetailDelete(slipNo,mtlNo);
    }

}
